package com.gonetbar.base.vo;

import java.util.List;
import java.util.Map;

public class PageBean {

	public PageBean() {
	}

	public PageBean(int currentlyPage, int pageSize, Map statMap)
			throws Exception {
		this.pageSize = pageSize <= 0 ? 1 : pageSize;
		try {
			this.countResults = Integer.parseInt(statMap.get("COUNT_RESULTS")
					.toString());
			statMap.remove("COUNT_RESULTS");
		} catch (Exception e) {
			throw new Exception("Can't Not Init count_Results In PageBean ", e);
		}
		this.statMap = statMap;
		this.totalPage = countResults / pageSize + 1;

		if (currentlyPage <= 0) {
			this.currentlyPage = 1;
		} else if (currentlyPage > this.totalPage) {
			this.currentlyPage = totalPage;
		} else {
			this.currentlyPage = currentlyPage;
		}
		this.start = (this.currentlyPage - 1) * this.pageSize + 1;
		this.end = this.currentlyPage * this.pageSize;
		if (this.currentlyPage == 1)
			this.upPage = false;
		if (this.currentlyPage == this.totalPage)
			this.nextPage = false;

	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getEnd() {
		return end;
	}

	public void setEnd(int end) {
		this.end = end;
	}

	private boolean nextPage = true;
	private boolean upPage = true;
	private int totalPage;
	private int countResults;
	private int currentlyPage;
	private Map statMap;
	private List dataList;
	private int start;
	private int end;
	private int pageSize = 20;

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public boolean isNextPage() {
		return nextPage;
	}

	public void setNextPage(boolean nextPage) {
		this.nextPage = nextPage;
	}

	public boolean isUpPage() {
		return upPage;
	}

	public void setUpPage(boolean upPage) {
		this.upPage = upPage;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getCountResults() {
		return countResults;
	}

	public void setCountResults(int countResults) {
		this.countResults = countResults;
	}

	public int getCurrentlyPage() {
		return currentlyPage;
	}

	public void setCurrentlyPage(int currentlyPage) {
		this.currentlyPage = currentlyPage;
	}

	public Map getStatMap() {
		return statMap;
	}

	public void setStatMap(Map statMap) {
		this.statMap = statMap;
	}

	public List getDataList() {
		return dataList;
	}

	public void setDataList(List dataList) {
		this.dataList = dataList;
	}

}
